<cftry>
<cfsilent>
	<!--- Only allow logged in users of type s2 and s2private --->
	<!--- Also, allow the server for cron jobs --->
	<cfif NOT ListFind('10.3.0.1',cgi.Remote_Addr)>
		<cfif (NOT isUserInRole('s2isPrivate')
			OR NOT isDefined('request.stAccountInfo.qryGetAccount')
			OR NOT isYSS(request.stAccountInfo.qryGetAccount.nAccountsID))>
			<cflocation url="/admin/index.cfm?fuseaction=cLogin.main&returnURL=#URLEncodedFormat(cgi.script_Name & '?' & cgi.query_string)#" addToken="false" />
			<cfabort />
		</cfif>
	
		<!--- Lock the customer in the customer UI --->
		<cfif NOT isUserInRole('s2')
			AND (isDefined('url.SubAction') AND url.SubAction NEQ '' AND (url.SubAction NEQ 'view_post_summary' AND isUserInRole('s2isPrivate'))
			OR (isDefined('url.inc') AND url.inc NEQ ''))>
			<cflocation url="/admin/index.cfm?fuseaction=cYSS.Main&siteid=#request.siteid#" addToken="false" />
			<cfabort />
		</cfif>
	<cfelse>
		<cfparam name="url.SubAction" default="" type="string" />
		<cfparam name="url.Inc" default="" type="string" />
	</cfif>

	<!--- Set some production vars --->	
	<cfset request.YSSProd = true />
	<cfset request.Beta = true />
	<cfset request.Debugging = false />
	<cfset request.DebugListingPoster = false />
	<cfset request.DebugMarketStatPoster = false />
	<cfset request.DebugWelcomePostPoster = false />
	
	<!--- Set some administrative stuff here --->
	<cfset request.YSSReportEmails = 'alain@yourmlssearch.com,tim@yourmlssearch.com,ProjectManager@YourMLSsearch.com' />
	<cfset request.isYSSSuperAdmin = IIF(isUserInRole('YSS super admin;yourcompany;0'),DE('true'),DE('false')) />
	
	<!--- Check to see if we need to reinit any vars --->
	<cfif NOT request.YSSProd 
		OR isDefined('url.refresh')
		OR NOT isDefined('application.dsnYSS')
		OR NOT isDefined('application.stYSSActionInfo')
		OR NOT isDefined('application.stYSSActioninfo.lstAllActions')>
		<cflock type="exclusive" timeout="15" scope="Application">
			<!--- Reloading application scope:<br /> --->
			<cfinclude template="incInitObjects.cfm" />
		</cflock>
	</cfif>

	<!--- Copy some data from application scope to request --->
	<cfset request.stFieldlists = Duplicate(application.YSSData.stFieldLists) />
	<cfset request.stYSSFieldTranslation = Duplicate(application.YSSData.stYSSFieldTranslation) />

	<!--- Get the account ID from YMLS if exists --->
	<cfset request.theYMLSAccountID = request.stAccountInfo.qryGetAccount.nAccountsID />
	<cfset request.qryGetYSSAccounts = application.YSSAccountManager.getYSSAccountBynAccountsID(request.theYMLSAccountID) />
	<cfset request.YSSAccountBean = createObject('component','cfcs.YSSAccountBean').init() />
	<cfset request.YSSAccountBean.set(request.qryGetYSSAccounts) />

	<!--- Load udfs ---> 
	<cfinclude template="udf_YSS.cfm" />
</cfsilent>

<!--- Sandbox: --->
<cfif (cgi.Remote_Addr EQ 'xxx.xxx.xxx.xxx'
	OR isDefined('url.altest'))
	AND isDefined('url.showdump')>

<!--- <cfset d(GetMetaData(application.postManager)) /> --->
<!--- <cfset d(application.postFactory.GetPendingPostsByntYSSAccountID(72,'','',true)) /> --->


<!--- *********Simulate post to ListingsBlog********* --->
<!--- <cfset wp = createObject('component','cfcs.api.wordpressposter').init('admin','gatsby##1') /> --->
<!--- <cfset stPostData = structNew() /> --->
<!--- <cfset stPostData.vcService_URL = 'http://timrivard.listingsblog.com/' /> --->
<!--- <cfset stPostData.VCOAUTHACCESSTOKEN = 'test' /> --->
<!--- <cfset stPostData.txBody = 'This is the body of the post...' /> --->
<!--- <cfset stPostData.vcTitle = 'This is the title of the post...' /> --->
<!--- <cfset stPostData.vcTags = 'These,are,the,tags' /> --->
<!--- <cfset doPost = wp.post(stPostData) /> --->
<!--- <cfset d(doPost) /> --->
<!--- ********* //Simulate post to ListingsBlog********* --->



<!--- <cfset d(application.listingfactory.getListingLink(431425,'sfitzmaurice','test','sup','www.RealEstateAgentPDX.com',0)) /> --->
<!--- 	<cfset request.listingsbean = CreateObject('component','cfcs.listingsbean').init() /> --->
<!--- 	<cfset request.qryGetListing = application.ListingsManager.getOne(26813072) /> --->
<!--- 	<cfset request.listingsbean.set(request.qryGetListing) /> --->
<!--- 	<cfset request.listingsbean.setvcCity('') /> --->
<!--- 	<cfset request.listingsbean.setvcZipcode('') /> --->
<!--- 	<cfset request.listingsbean.setvcAddress1('') /> --->
<!---  --->
<!--- 	<cfdump var="#application.listingFactory.getListingLink_mod1(28579664,'rick_sterling','123','IDX','http://exitrealtyhr.com/',2,request.listingsbean)#" /><hr /> --->
<!--- 	<cfdump var="#application.listingFactory.getListingLink_mod1(28579664,'janeagentYSS','123','IDX','jane_agent.nebdev.net/',0,request.listingsbean)#" /><hr /> --->
<!--- 	<cfdump var="#application.listingFactory.getListingLink_mod1(28579664,'janeagentYSS','123','Sup','net/',1,request.listingsbean)#" /><hr /> --->
<!--- 	<cfset d(application.listingFactory.getListingLink_mod1(28579664,'janeagentYSS','123','IDX','jane_agent.nebdev.net/',2,request.listingsbean)) /> --->

</cfif>
<!--- //Sandbox: --->

<cfif FindNoCase('iPhone',cgi.http_user_agent) or isDefined('url.iphonetest') or FindNoCase('Android',cgi.http_user_agent)>
	<cfinclude template="iphone/index.cfm" />
<cfelse>
	<!--- Handle design stuff --->
	<cfif isDefined('url.Del_YSSNoDesign')>
		<cfcookie name="YSSNoDesign" expires="NOW" value="false" />
	</cfif>
	
	<!--- For now, include the styles. later put them in a .css --->
	<cfinclude template="incYSSStyles.css" />
	
	<cfif NOT isDefined('url.YSSAjax')>
		<cfif request.qryGetYSSAccounts.RecordCount>
			<cfoutput>
			<cfif NOT isDefined('request.siteid') OR request.siteid EQ ''>
				<h3>Sorry, siteid is required and was not passed. Please try again.</h3>
			<cfelseif isDefined('url.subAction') AND Len(url.SubAction)>
				<cfset application.YSSUtil.InitSubAction(url.SubAction) />
				<cfinclude template="incMainNavigation.cfm" />
				<div style="clear:both;"></div>
				<cfinclude template="incAdvancedNavigation.cfm" />
				<div style="clear:both;"></div>
				<hr style="border:0px none;height:1px;background:##EFEFEF;" />
				
				<div style="float:left;">
				<cfif isDefined('form.btnSubmit') 
					OR (isDefined('url.Do') AND url.Do EQ 'delete')
					OR (isDefined('url.Do') AND url.Do EQ 'resetpost')>
					<cfset strOut = application.YSSUtil.ProcessFormSubmission(form,url) />
					#strOut#
					<cftry>
						<cfinclude template="dsp_#ListFirst(url.SubAction,'_')#_Master.cfm" />
						<cfcatch type="MissingInclude">
							Sorry, we couldn't find the page you were looking for.
							<!--- <cfdump var="#cfcatch#"> --->
						</cfcatch>
					</cftry>
				<cfelse>
					<cfif isDefined('url.msg') AND Len(url.msg)>
						<h3 id="ResultMsg">#url.msg#</h3>
					</cfif>
					<cfinclude template="dsp_#ListFirst(url.SubAction,'_')#_Master.cfm" />
				</cfif>
				</div>
			<cfelseif isDefined('url.Inc')>
				<cfinclude template="incMainNavigation.cfm" />
				<div style="clear:both;"></div>
				<cfinclude template="incAdvancedNavigation.cfm" />
				<div style="clear:both;"></div>
				<cfif Len(url.inc)>
					<cftry>
						<cfset wl('Starting: #url.inc#.',url.inc) />
						<cfinclude template="inc_#url.inc#.cfm" />
						<cfset wl('Ending: #url.inc#.',url.inc) />
						<cfcatch type="MissingInclude">
							Sorry, we couldn't find the page you were looking for.
							<cfset wl('Missing include: #url.inc#.',url.inc) />
							<!--- <cfdump var="#cfcatch#"> --->
						</cfcatch>
					</cftry>
				</cfif>
			<cfelse>
				<cfif isUserInRole('s2')>
					<cfif isDefined('cookie.YSSNoDesign')
						AND NOT cookie.YSSNoDesign>
						<div style="width:100%;margin:0 auto;">
							<cfinclude template="incMainNavigation.cfm" />
							<div style="clear:both;"></div>
							<cfinclude template="incAdvancedNavigation.cfm" />
							<div style="clear:both;padding-bottom:40px;"></div>
						</div>
					<cfelse>
						<div style="clear:both;padding-bottom:20px;"></div>
					</cfif>
				</cfif>
	
				<cfif isDefined('form.btnSubmit')>
					<cfset request.strPostMessage = application.YSSUtil.ProcessFormSubmission(form,url) />
				</cfif>
				
				<div<cfif isDefined('cookie.YSSNoDesign') AND cookie.YSSNoDesign IS TRUE>style="width:100%;margin:0 auto;"</cfif>>
					<cfif isUserInRole('s2')>
						<div id="navs" style="width:100%;margin:0 auto;display:;clear:both;margin-top:10px;">
							<cfinclude template="incMainNavigation.cfm" />
							<div style="clear:both;"></div>
							<cfinclude template="incAdvancedNavigation.cfm" />
							<div style="clear:both;padding-bottom:40px;"></div>
						</div>
					</cfif>				
					<cfinclude template="dspClientUI.cfm" />
					<div style="padding:4px;">
						<a href="/admin/index.cfm?fuseaction=cYSS.main&amp;siteid=#request.siteid#&YSSNoDesign=True">View without YMLS CP</a> /
						<a href="/admin/index.cfm?fuseaction=cYSS.main&amp;siteid=#request.siteid#&del_YSSNoDesign=True">View with YMLS CP</a>
				<cfif isUserInRole('s2')>/
					<div><a href="javascript:void(0);" onclick="$('AdvNav').toggle();return false;">Show/Hide Navigation</a></div>
					<div id="AdvNav" style="width:100%;margin:0 auto;display:none;clear:both;margin-top:10px;">
						<cfinclude template="incMainNavigation.cfm" />
						<div style="clear:both;"></div>
						<cfinclude template="incAdvancedNavigation.cfm" />
						<div style="clear:both;padding-bottom:40px;"></div>
					</div>
				</cfif>

						<div style="clear:both;"></div>
					</div>
				</div>
				
			</cfif>
			</cfoutput>
		<cfelse>
			<h2>YourFeed.net:</h2>
			<cfif isUserInRole('s2')>
				<cfif isDefined('url.subaction') AND url.subAction EQ 'Enable_Account' AND isDefined('request.theYMLSAccountID') AND isNumeric(request.theYMLSAccountID) AND request.theYMLSAccountID GT 1>
					<cfset application.YSSUtil.EnableAccount(request.theYMLSAccountID,request.SiteID) />
				</cfif>
				<cfoutput>YourFeed.net has not been enabled for this account. Click <a href="#cgi.Script_Name#?fuseaction=cYSS.main&siteid=#url.SiteID#&subAction=Enable_Account&nAccountsID=#request.theYMLSAccountID#">here</a> to enable this account.</cfoutput>
			<cfelse>
				Sorry, it doesn't look like your account has been setup. Please contact an administrator for assistance.
			</cfif>
		</cfif>
	<cfelse>
		<cfinclude template="dsp_#url.SubAction#.cfm" />
	</cfif>
</cfif>

	<cfcatch type="any">
		<div style="height:5000px;width:1000px;overflow:auto;">
			<cfdump var="#cfcatch#">
		</div>
	</cfcatch>
</cftry>

<cffunction name="isYSS">
	<cfargument name="nAccountsID" />
	
	<cfquery name="q" datasource="#application.dsn#">
	SELECT TOP 1 * FROM YSS.dbo.tblYSSAccount
	WHERE nAccountsID = #arguments.nAccountsID#
	AND btActive = 1
	</cfquery>
	
	<cfreturn q.RecordCount />
	
</cffunction>